package love.xin.adapter


import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import love.xin.databinding.EventItemBinding
import love.xin.entity.Event
import love.xin.util.DataUtil.Companion.getEventData


class EventAdapter (private val context: Context ) : RecyclerView.Adapter<EventAdapter.ViewHolder>() {
    private val list = getEventData()
    inner class ViewHolder(private val bin: EventItemBinding) : RecyclerView.ViewHolder(bin.root) {

        fun bind(event: Event) {
           bin.text.text = event.title
            bin.image.setBackgroundResource(event.img)

        }
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        return ViewHolder(EventItemBinding.inflate(LayoutInflater.from(parent.context), parent, false))

    }

    override fun getItemCount(): Int =list.size

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        holder.bind(list[position])
    }


}
